package com.time;

import com.onelogin.saml2.Auth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author yonghao.tang
 */
@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    private static final Logger log = LoggerFactory.getLogger(LoginServlet.class);
    
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            //构造Auth客户端，默认使用classpath下的onelogin.saml.properties，也可指定文件
            Auth auth = new Auth(request, response);
            //RelayState 回调URL
            //auth.login(relayState);
            auth.login();
        } catch (Exception e) {
            log.error("login with yonghao's okta failed", e);
        }
    }
}
